//
//  Status.swift
//  新浪微博
//
//  Created by 焦林生 on 15/11/10.
//  Copyright © 2015年 焦林生. All rights reserved.
//

import UIKit

//微博数据模型
class Status: NSObject {

    
    //微博ID
    var id: Int = 0
    //微博信息内容
    var text: String?
    //微博创建时间]
    var created_at: String?
    //微博来源
    var source: String? {
    
        didSet {
        
            source = source?.href()?.text
        }
    }
    //用户模型
    var user: User?
    //缩略图片字典数组地址
    var pic_urls:[[String: String]]?
   //被转发的原微博模型属性
    var retweeted_status: Status?
    
    //kvc 字典转模型
    init(dict: [String: AnyObject]) {
        super.init()
        
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        //1 判断key是否是user
        if key == "user" {
        
            if let dict = value as? [String: AnyObject] {
            
                user = User(dict: dict)
            }
            return
        }
        
        //2 判断 key 是否等于retweeted_status
        if key == "retweeted_status" {
        
            if let dict = value as? [String: AnyObject] {
            
                retweeted_status = Status(dict: dict)
            }
            return
        }
        
        super.setValue(value, forKey: key)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
    override var description: String {
    
        let keys = ["id", "text", "created_at", "source","user", "pic_urls", "retweeted_status"]
        
        return dictionaryWithValuesForKeys(keys).description
    }
    
}
